/**
 * 模拟销毁
 */
import React,{Component, useEffect, useState} from 'react';
function Children() {
    const [name,setname] =useState("peng-ke")
    useEffect(()=>{
        window.onresize=()=>{
            console.log("resize")
        }
        let timer=setInterval(() => {
            console.log("ppppp")
        }, 1000);
        return ()=>{
            console.log("销毁");
            window.onresize=null;
            clearInterval(timer)
        }
    },[])
    return (
        <div>
            碰磕
        </div>
    );
}

class Test4 extends Component{
    state={
        iscreated:true
    }
    render(){
        return(
            <div>
                <button onClick={()=>{
                    this.setState({
                        iscreated:!this.state.iscreated
                    })
                }}>点我</button>
                {this.state.iscreated && <Children />}
            </div>
        )
    }
}

export default Test4;